/**
 * 
 */
package hb_Teach_InitObject_MarryPractice01;

/**
 * @author Jiang Zhiyan
 *
 * 2021年4月23日 上午9:09:31
 */
public class Person{
//	定义对象名称
	   private String idCard;
	   private String name;
	   private String sex;
	   private int age;
	   private boolean married;
	   private Person other;
	   
//	   无参构造器
	   public Person() {
	   }

/**
 * @param idCard
 * @param name
 * @param sex
 * @param age
 */
public Person(String idCard, String name, String sex, int age) {
//	super(); java的类存在一个默认的父类Object
//	一定要赋值  alt+s ...with fields
	this.idCard=idCard;
	this.name = name;
	this.sex = sex;
	this.age = age;
}
/**
 * @return the idCard
 */
public String getIdCard() {
	return idCard;
}

/**
 * @param idCard the idCard to set
 */
public void setIdCard(String idCard) {
	this.idCard = idCard;
}

  /**
 * @return the name
 */
public String getName() {
	return name;
}

/**
 * @param name the name to set
 */
public void setName(String name) {
	this.name = name;
}

/**
 * @return the sex
 */
public String getSex() {
	return sex;
}

/**
 * @param sex the sex to set
 */
public void setSex(String sex) {
	this.sex = sex;
}

/**
 * @return the age
 */
public int getAge() {
	return age;
}

/**
 * @param age the age to set
 */
public void setAge(int age) {
	this.age = age;
}

/**
 * @return the married
 */
public boolean isMarried() {
	return married;
}

/**
 * @param married the married to set
 */
public void setMarried(boolean married) {
	this.married = married;
}

/**
 * @return the other
 */
public Person getOther() {
	return other;
}

/**
 * @param other the other to set
 */
public void setOther(Person other) {
	this.other = other;
}

public Person(boolean married,Person other) {
	  this.married=married;
	  this.other=other;
  }
//定义方法
//    判断：1、两人年龄必须大于20；
//         2、两人异性；
//         3、两人均未结婚

public boolean marryWith(Person p) {
//	判断p是否存在
	if(p==null) {
		System.out.println("对象不存在");
		return false;
	}
	boolean agepd=this.age>=20&&p.age>=20;
	boolean sexpd=!this.sex.equals(p.sex);
//	boolean sexpd=this.sex!=p.sex; 字符串判断相等不能直接判断，必须使用equals方法
	boolean marrypd=!this.married&&!p.married;
	if(agepd&&sexpd&&marrypd) {
//		对结婚的状态进行修改
		this.married=true;
		p.married=true;
//		设置伴侣
		this.other=p;
		p.other=this;
		System.out.println("喜结连理");
		return true;
	}
	return false;
}



}